<template>
  <div>
    <div style="margin-top: -90px;margin-bottom: -20px">修改材料</div>
    <el-form :model="ruleForm" :rules="rules" ref="ruleForm" label-width="100px">
      <div style="margin-right: 125px;margin-left: 55px">
        <el-form-item label="公司名称" prop="company_name" >
          <el-input v-model="ruleForm.company_name"></el-input>
        </el-form-item>
        <el-form-item label="公司电话" prop="company_phone">
          <el-input v-model="ruleForm.company_phone"></el-input>
        </el-form-item>
      </div>
      <el-form-item style="margin-left: -90px">
        <el-button type="primary" @click="submitForm('ruleForm')">修改</el-button>
        <el-button @click="resetForm('ruleForm')">重置</el-button>
      </el-form-item>
    </el-form>
  </div>
</template>

<script>
import {editCompany} from "@/api/drugCP";

export default {
  data() {
    return {
      ruleForm: {
        company_id:0,
        company_phone: '',
        company_name: '',
      },
      rules: {
        company_name: [{ required: true, message: '请输入公司名称', trigger: 'blur' }],
        company_phone: [{ required: true, message: '请输入公司电话', trigger: 'blur' }],
      }
    };
  },
  props:["myForm"],
  methods: {
    submitForm(formName) {
      this.$refs[formName].validate((valid) => {
        if (valid) {
          editCompany(this.ruleForm).then(res=>{
            if(res.code==200){
              //修改成功
              this.$message({type:'success',message:res.msg})
              this.$emit("closeEditDialog")
            }else{
              //修改失败
              this.$message({type:'error',message:res.msg})
            }
          }).catch(error=>{})
        } else {
          console.log('error submit!!');
          return false;
        }
      });
    },
    resetForm(formName) {
      this.$refs[formName].resetFields();
    },
    showData(){
      this.ruleForm.company_id=this.myForm.company_id
      this.ruleForm.company_name=this.myForm.company_name
      this.ruleForm.company_phone=this.myForm.company_phone
    }
  }
}
</script>

<style scoped>

</style>
